from editor . logic import editor_logic

class mediator_fake :
    def __init__ ( self ) :
        self . _editor_logic = None
        self . _add_title_label_to_editor = [ ]
        self . _editor_menu_button = False
        self . _key_escape_counter = None
    def add_title_label_to_editor ( self , base_name ) :
        self . _add_title_label_to_editor += [ base_name ]
    def on_editor_menu_button ( self ) :
        self . _editor_menu_button = True
    def key_escape_counter_request ( self ) :
        self . _editor_logic . key_escape_counter_reply ( self . _key_escape_counter )

class editor_logic_tests :
    'editor_logic'
    def __init__ ( self , test ) :
        self . _test = test
        self . _mediator = mediator_fake ( )
        self . _editor_logic = editor_logic ( self . _mediator )
        self . _mediator . _editor_logic = self . _editor_logic
    def test_show_editor ( self ) :
        self . _editor_logic . select_knowledge_base_for_editing ( 'my base' )
        self . _editor_logic . show_editor ( )
        self . _test . assume_equal ( self . _mediator . _add_title_label_to_editor , [ 'my base' ] )
    def test_save_knowledge_base_in_editor ( self ) :
        self . _test . assume_equal ( self . _editor_logic . save_knowledge_base_in_editor ( ) , None )
    def test_save_as_knowledge_base_in_editor ( self ) :
        self . _test . assume_equal ( self . _editor_logic . save_as_knowledge_base_in_editor ( None ) , None )
    def test_on_key_escape_editor_menu_button ( self ) :
        self . _mediator . _key_escape_counter = 'my old counter'
        self . _editor_logic . show_editor ( )
        self . _mediator . _key_escape_counter = 'my new counter'
        self . _editor_logic . on_key_escape ( )
        self . _test . assume_true ( self . _mediator . _editor_menu_button )
    def test_on_key_escape_after_hide ( self ) :
        self . _mediator . _key_escape_counter = 'my old counter'
        self . _editor_logic . show_editor ( )
        self . _mediator . _key_escape_counter = 'my new counter'
        self . _editor_logic . hide_editor ( )
        self . _editor_logic . on_key_escape ( )
        self . _test . assume_false ( self . _mediator . _editor_menu_button )
    def test_on_key_escape_before_show ( self ) :
        self . _editor_logic . on_key_escape ( )
        self . _test . assume_false ( self . _mediator . _editor_menu_button )
    def test_on_key_escape_after_show_same_counter ( self ) :
        self . _mediator . _key_escape_counter = 'my counter'
        self . _editor_logic . show_editor ( )
        self . _editor_logic . on_key_escape ( )
        self . _test . assume_false ( self . _mediator . _editor_menu_button )
